<?php
// +----------------------------------------------------------------------
// | 地址
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v3;

use app\model\app\Modular;
use app\model\store\Address as AddressModel;
use app\event\store\Address as AddressEvent;
use app\model\store\Region;
use app\model\ucenter\User as UserModel;
use yicmf\tools\HttpService;
use app\event\cms\Document as DocumentEvent;
use app\model\cms\Article as ArticleModel;
use think\facade\Db;

class Document extends Common
{

    /**
     * 文章列表
     */
    public function lists()
    {
        $type = input('type/d', 1);
        $articleList = ArticleModel::where('type', $type)->where('status', 1)->select();
        return $this->successAjax($articleList);
    }

    /**
     * 文章列表
     */
    public function modular()
    {
        $modular_id = input('modular_id/d', 1);
        $articleList = ArticleModel::with('cover')->where('modular_id', $modular_id)->where('status', 1)->where('id','>',26)->paginate();
        $data['lists']= $articleList;
        $data['modular']= Modular::where('id', $modular_id)->find();
        return $this->successAjax($data);
    }

    /**
     * 获取通知时间
     * @return false|int
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getCreateTime()
    {
        $user = Db::name('user')->where('id', $this->auth->id)->find();
        return strtotime(date('Y-01-01 0:0:0', $user['createtime']));
    }

    /**
     * 文章详情
     */
    public function info()
    {
        $info = ArticleModel::where('id', input('id/d', 0))->where('status', 1)
            ->find();
        if ($info) {
            return $this->successAjax($info);
        } else {
            return $this->errorAjax('信息不存在');
        }
    }

    /**
     * 文章详情
     */
    public function detail()
    {
        $info = ArticleModel::where('id', input('id/d', 0))->where('status', 1)->find();
        if ($info) {
            return $this->successAjax($info);
        } else {
            return $this->errorAjax('信息不存在');
        }
    }

    /**
     * 文章详情
     */
    public function server()
    {
        $info = Db::name('service')->where('id', input('id/d', 0))->find();
        if ($info) {
            return $this->successAjax($info);
        } else {
            return $this->errorAjax('信息不存在');
        }
    }

    /**
     * 关于我们
     */
    public function about()
    {
        $info = ArticleModel::where('id', 26)
            ->find();
        return $this->successAjax($info);
    }
}
